import { createStore } from "vuex";

//创建状态
const state = {
    activePath: '666',
    userInfo: null, // 用户信息
    userRole: null, // 用户角色
    isAdmin: false // 是否为管理员
}
//创建actions
const actions = {

}
//创建mutataions
const mutations = {
    // activePath
    changeActivePath(state, newV) {
        // console.log('newV:' + newV)
        state.activePath = newV;
    },
    // 设置用户信息
    setUserInfo(state, userInfo) {
        state.userInfo = userInfo;
        state.userRole = userInfo?.role || null;
        state.isAdmin = userInfo?.role === 'ADMIN' || userInfo?.isAdmin === true;
    },
    // 清除用户信息
    clearUserInfo(state) {
        state.userInfo = null;
        state.userRole = null;
        state.isAdmin = false;
    }
}

//创建store
const store = createStore({
    state,
    actions,
    mutations
})
//暴露出去
export default store